CONFIG = Release
DIR= $(shell pwd) 

CXX= g++
CXXFLAGS += -Wall -pg -Wextra -I$(DIR) \
	-pedantic -Wmain -Wswitch-default -Wswitch-enum -Wmissing-include-dirs \
	-Wmissing-declarations -Winline -Wfloat-equal -Wundef -Wcast-align -Wredundant-decls -Winit-self \
	-Woverloaded-virtual 
LDFLAGS += -lm 

ifeq ($(CONFIG),Release)
	CXXFLAGS +=
	LDFLAGS += -O3 -static	
else
	CXXFLAGS += -g
	LDFLAGS += 
endif

SOURCES = genio.c genrmf.c genmain.c
EXECUTABLE = genrmf

OBJS = $(addprefix $(CONFIG)/,$(SOURCES:.c=.o))

MAKE = make
RM = rm -f
RM_DIR = rm -rf
MK_DIR = mkdir

all: $(EXECUTABLE)

genrmf: $(OBJS) Makefile create_dir 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) -o $(CONFIG)/$@

$(CONFIG)/%.o: %.c Makefile create_dir
	$(CXX) $(CXXFLAGS) -c $< -o $@
	
create_dir:
	$(shell [ ! -d  $(CONFIG) ] && $(MK_DIR) $(CONFIG))

clean:
	$(RM) $(CONFIG)/*
	$(shell [ -d $(CONFIG) ] && $(RM_DIR) $(CONFIG))
	
depend:	$(SOURCES)
	makedepend -m -I../ -Y *.c $^

# DO NOT DELETE THIS LINE -- make depend needs it

genio.o: gen_maxflow_typedef.h genio.h
genmain.o: gen_maxflow_typedef.h genio.h
genrmf.o: gen_maxflow_typedef.h genio.h math_to_gcc.h
genio.o: gen_maxflow_typedef.h genio.h
genrmf.o: gen_maxflow_typedef.h genio.h math_to_gcc.h
genmain.o: gen_maxflow_typedef.h genio.h
